package com.ruix.app.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ruix.app.R;

/**
 * Created by hadexs on 2017/4/30.
 */

public class DeletePostDialog extends Dialog implements View.OnClickListener{


    private String postid;
    private int position;
    private DeletePostListener listener;

    public DeletePostDialog( Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_delete_post);
        setCanceledOnTouchOutside(true);
        initEvent();
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;//宽高可设置具体大小
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);

    }

    private void initEvent(){
        TextView message = (TextView) findViewById(R.id.tv_common_message);
        message.setText("您确定删除该实践？");
        findViewById(R.id.btn_sure).setOnClickListener(this);
        findViewById(R.id.btn_cancel).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_sure:
                dismiss();
                if (listener != null){
                    listener.deletePostPositive(postid,position);
                }
                break;
            case R.id.btn_cancel:
                dismiss();

                break;
        }
    }

    public void setListener(DeletePostListener listener) {
        this.listener = listener;
    }


    public void show(String postID, int commentPosition) {
        this.postid = postID;
        this.position = commentPosition;
        show();
    }

    public interface DeletePostListener{
        void deletePostPositive(String postID, int commentPosition);
    }

}
